﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
using FrameWork;
using FrameWork.Components;

namespace FrameWork.web.Module.ITMS.Service.ServTrobType
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDataList();
                try
                {
                    int RecordCount = 0;
                    QueryParam qp = new QueryParam();
                    qp.Orderfld = "ID";
                    qp.OrderType = 0;
                    qp.Where = "Where 1=1 ";
                    ArrayList lst = BusinessFacade.its_ServProbTypeList(qp, out RecordCount);
                    DDLServProbTypeID.DataSource = lst;
                    DDLServProbTypeID.DataValueField = "ID";
                    DDLServProbTypeID.DataTextField = "Context";
                    DDLServProbTypeID.DataBind();
                }
                catch
                {

                }
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindDataList()
        {
            QueryParam qp = new QueryParam();
            qp.Where = SearchTerms;
            qp.PageIndex = AspNetPager1.CurrentPageIndex;
            qp.PageSize = AspNetPager1.PageSize;
            int RecordCount = 0;
            ArrayList lst = BusinessFacade.its_ServTrobTypeList(qp, out RecordCount);
            DataTable dtServTrobType = new DataTable();
            dtServTrobType.Columns.Add("ID");
            dtServTrobType.Columns.Add("Context");
            dtServTrobType.Columns.Add("ServProbTypeID");
            dtServTrobType.Columns.Add("ServProbTypeName");
            //得到问题分类信息
            ArrayList lstProbType = getProbType();
            foreach (object item in lst)
            {
                DataRow dr = dtServTrobType.NewRow();
                dr["ID"] = ((its_ServTrobTypeEntity)item).ID; 
                dr["Context"] = ((its_ServTrobTypeEntity)item).Context;
                dr["ServProbTypeID"] = ((its_ServTrobTypeEntity)item).ServProbTypeID;
                foreach (object itemProbType in lstProbType)
                {
                    if (((its_ServProbTypeEntity)itemProbType).ID == ((its_ServTrobTypeEntity)item).ServProbTypeID)
                    {
                        dr["ServProbTypeName"] = ((its_ServProbTypeEntity)itemProbType).Context;
                        break;
                    }
                }
                dtServTrobType.Rows.Add(dr);
            }
            GridView1.DataSource = dtServTrobType;
            GridView1.DataBind();
            this.AspNetPager1.RecordCount = RecordCount;
        }

        /// <summary>
        /// 点击分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindDataList();
        }

        /// <summary>
        /// 查询条件
        /// </summary>
        private string SearchTerms
        {
            get
            {
                if (ViewState["SearchTerms"] == null)
                    ViewState["SearchTerms"] = " Where 1=1 ";
                return (string)ViewState["SearchTerms"];
            }
            set { ViewState["SearchTerms"] = value; }
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            string Context_Value = (string)Common.sink(Context_Input.UniqueID, MethodType.Post, 500, 0, DataType.Str);
            string ServProbTypeID_Value = (string)Common.sink(DDLServProbTypeID.UniqueID, MethodType.Post, 10, 0, DataType.Str);
            StringBuilder sb = new StringBuilder();
            sb.Append(" Where 1=1 ");

            if (Context_Value != string.Empty)
            {
                sb.AppendFormat(" AND Context like '%{0}%' ", Common.inSQL(Context_Value));
            }

            if (ServProbTypeID_Value != string.Empty)
            {
                sb.AppendFormat(" AND ServProbTypeID = {0} ", Convert.ToInt32(ServProbTypeID_Value));
            }
            ViewState["SearchTerms"] = sb.ToString();
            BindDataList();
            TabOptionWebControls1.SelectIndex = 0;
        }


        /// <summary>
        /// 得到问题类型
        /// </summary>
        /// <returns></returns>
        private ArrayList getProbType()
        {
            QueryParam qp = new QueryParam();
            qp.Where = "where 1=1";
            int RecordCount = 0;
            ArrayList lst = BusinessFacade.its_ServProbTypeList(qp, out RecordCount);
            return lst;
        }
    }
}
